<script type="text/javascript">
	/* set defaults */
	var current = 1.4;

	/* if the settings were more thought out in the beginning this
	would make a bit more sense, but we can safely assume that
	having set the destination means the extension was installed.

	then at version 0.2 dynamic destination was added, so
	only that needs to be set
	
	at version 1.2 an option was added to allow disabling
	the double-click action */

	if(localStorage["destination"] == null) { /* first run */
		/* accelerators */
		localStorage["accel.alt"] = false;
		localStorage["accel.ctrl"] = true;
		localStorage["accel.shift"] = true;
		localStorage["accel.key"] = 65; /* CTRL SHIFT a */

		/* destination */
		localStorage["destination"] = "destination.default";
		localStorage["destination.path"] = "";
		localStorage["destination.dpath"] = "";
		
		/* other */
		localStorage["other.doubleclick"] = true;
		localStorage["other.autostart"] = true;
		localStorage["other.onebyone"] = false;
	}
	if(localStorage["version"] < 0.2) {
		localStorage["destination.dpath"] = "";
	}
	if(localStorage["version"] < 1.2) {
		localStorage["other.doubleclick"] = true;
	}
	localStorage["version"] = current;

	chrome.extension.onRequest.addListener(
		function(request, sender, callback) {
			if(request.command == "getOptions") {
				callback({
						command : request.command,
						destination : localStorage["destination"],
						destinationPath : localStorage["destination.path"],
						dynamicPath : localStorage["destination.dpath"],
						autostart : localStorage["other.autostart"] == "true",
						oneByOne : localStorage["other.onebyone"] == "true",
						doubleClick : localStorage["other.doubleclick"] == "true",
						accelKey : parseInt(localStorage["accel.key"]),
						accelAlt : localStorage["accel.alt"] == "true",
						accelCtrl : localStorage["accel.ctrl"] == "true",
						accelShift : localStorage["accel.shift"] == "true"
				});
			}
			else if(request.command == "saveDynamicPath") {
				localStorage["destination.dpath"] = request.dynamicPath;
				callback({});
			}
			else {
				callback({});
			}
		}
	);
</script>
